﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using System.Web.Routing;

namespace MvcRags.Core
{
    public static class SecurityTrimmedLink
    {
        public static MvcHtmlString SecurityTrimmedActionLink(this HtmlHelper htmlHelper, string linkName, string actionName)
        {
            return htmlHelper.HasActionPermission(actionName, "")
                       ? htmlHelper.ActionLink(linkName, actionName)
                       : MvcHtmlString.Create("");
        }

        public static MvcHtmlString SecurityTrimmedActionLink(this HtmlHelper htmlHelper, string linkName, string actionName, RouteValueDictionary routeValueDictionary)
        {
            return htmlHelper.HasActionPermission(actionName, "")
                       ? htmlHelper.ActionLink(linkName, actionName, routeValueDictionary)
                       : MvcHtmlString.Create("");
        }

        public static MvcHtmlString SecurityTrimmedActionLink(this HtmlHelper htmlHelper, string linkName, string actionName, object routeValues, object htmlAttributes)
        {
            return htmlHelper.HasActionPermission(actionName, "")
                       ? htmlHelper.ActionLink(linkName, actionName, routeValues, htmlAttributes)
                       : MvcHtmlString.Create("");
        }

        public static MvcHtmlString SecurityTrimmedActionLink(this HtmlHelper htmlHelper, string linkName, string actionName, string controllerName)
        {
            return htmlHelper.HasActionPermission(actionName, controllerName)
                       ? htmlHelper.ActionLink(linkName, actionName, controllerName)
                       : MvcHtmlString.Create("");
        }
    }
}
